package Database;
import java.sql.*;
import java.util.ArrayList;

import Model.Diploma;

public class DiplomaDB {

	public static ArrayList<Diploma> getAllDiploma()
	{
		Connection con = DBConnection.connect(true);
		PreparedStatement stmt = null;
		ResultSet rs = null;
		String select = "SELECT * FROM diploma ORDER BY Dip_Name";

		ArrayList<Diploma> dipArr = new ArrayList<Diploma>();
		Diploma diploma = null;

		try
		{
			stmt = con.prepareStatement(select);
			// stmt.setString(1, credID);
			rs = stmt.executeQuery();
			while (rs.next())
			{
				diploma = new Diploma();
				diploma.setDip_code(rs.getString("Dip_Code"));
				diploma.setDip_name(rs.getString("Dip_Name"));
				dipArr.add(diploma);
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			diploma = null;
		}
		finally
		{
			try
			{
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			}
			catch (SQLException e)
			{
			}
		}

		return dipArr;
	}
	
}
